#!/bin/bash

# Quick and dirty script for releasing all the built SDKs
# This will eventually be updated by task inside of gradle

usage() {
    echo "Usage: "
    echo "  stageAllSDK [SDKDIR] [TARGETDIR]"
    echo "Example: "
    echo "  ./stageAllSDK ../build/smithyprojections/sdk-codegen ../../../AlphaSwiftSDK"
}

SDKDIR=$1
TARGET=$2

if [ $# -ne 2 ]; then
    usage
    exit 1
fi

if [ ! -d ${SDKDIR} ]; then
   echo "Could not find ${SDKDIR}"
   exit 1
fi


if [ ! -d ${TARGET} ]; then
    echo "Directory needs to be present: ${TARGET}"
    exit 1
fi

for sdk in `ls ${SDKDIR} | grep -vw "source" `; do
    cp -R ${SDKDIR}/$sdk/swift-codegen/* ${TARGET}/.
    rm -Rf ${TARGET}/.build
    rm -f ${TARGET}/Package.swift
    rm -f ${TARGET}/Package.resolved
done
